package startup

import (
	"github.com/spf13/viper"
	"gorm.io/driver/postgres"
	"gorm.io/gorm"
)

var db *gorm.DB

func InitTestDB() *gorm.DB {
	if db == nil {
		dsn := "host=10.151.5.134 user=postgres password=stmedical dbname=book port=6433 sslmode=disable TimeZone=Asia/Shanghai"
		dbs, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
		db = dbs
		if err != nil {
			panic(err)
		}
	}
	return db
}

func InitViper() {
	//viper.AddConfigPath("D:\\goProject\\booksmart\\book\\config\\")
	viper.SetConfigFile("D:\\goProject\\booksmart\\book\\config\\dev.yaml")
	viper.SetConfigType("yaml")
	err := viper.ReadInConfig()
	if err != nil {
		panic(err)
	}

}
